<?php
/**
 *	@func 链接数据库
 */
class db{
	public $linkID = null;		//链接ID
	public $config = array();	//链接信息
	
	public function __construct(){
		$this->config = include('config.php');
		$this->connect();
	}
	
	
	/**
	 *	@func 数据库链接
	 */
	public function connect(){
		$C = $this->config;
		$this->linkID = mysql_connect($C['DB_HOST'], $C['DB_USER'], $C['DB_PWD']);
		mysql_select_db($C['DB_NAME'], $this->linkID);
		mysql_query('SET NAMES '.$C['DB_CHARSET'], $this->linkID);//设置字符集
	}
	
	/**
	 *	@func 数据库查询
	 *	@param string $sql 查询字符串
	 *	@ret 关联数据返回
	 */
	public function query($sql){
		$res = mysql_query($sql, $this->linkID);
		if(!$res){
			exit('query error:'.mysql_error());
		}
		return true;
	}

	
	
}

//$db = new db();
//$data = $db->query('select * from client_info');
//$data = $db->query("INSERT INTO `client_info`(id, website, website_url, websit_in, website_out, client_ip)	VALUES(null,'2','2','2','2','2')");
//var_dump($data);
?>